/*
day126
2020.1.1
*/
#include<vector>
#include<iostream>
using namespace std;

class Solution {
public:
    int findMin(vector<int>& nums) 
	{
        if(nums.size()==1) return nums[0];
        
        if(nums[0] < nums[nums.size()-1]) return nums[0];
        
        int point;
        
        int l=1,r=nums.size()-1;
    	int mid;
    	
    	while(l<=r)
    	{
    		mid=l+(r-l)/2;
//    		cout<<l<<'\t'<<r<<'\t'<<mid<<'\t'<<nums[mid]<<endl;
    		if(nums[mid]<nums[mid-1]) 
    		{
    			point = mid;
    			break;
			}
			
			if(nums[mid] > nums[0])
			{
				l=mid+1;
			}
			
			else
			{
				r=mid-1;
			}
		}
        
        return nums[point];
    }
};


class Solution2 {
public:
    int findMin(vector<int>& nums) 
	{
		int min=nums[0];
        for(int i=1;i<nums.size();i++)
        {
        	if(nums[i]<min)
        	{
        		min=nums[i];
			}
		}
		
		return min;
    }
};


class Solution3 {
public:
    int findMin(vector<int>& nums) 
	{
        
    }
};
int main()
{
	vector<int> nums={4,5,6,7,0,1,2};
	Solution s;
	cout<<s.findMin(nums);
	return 0;
}
